import Vue from "vue"
import Vuex from 'vuex'
// vue插件的语法
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    num:10
  },
  mutations: {
    addNum(state,{num1,num2}){
      console.log(num1,num2);
      state.num+=num1;
    },
    reduceNum(state){
      state.num--
    }
  },
  getters: {
    num2(state) {
      return state.num*2
    }
  },
  actions:{
    /* add_num(context){ //context就是store 
      context.commit('addNum',{num1:5,num2:6});
    } */
    /* add_num({commit}){ //context就是store 
      commit('addNum',{num1:5,num2:6});
    }  */
    add_num({commit}){ //context就是store 
      setTimeout(() => {
        commit('addNum',{num1:5,num2:6});
      }, 2000);
    }
   
  }
})

export default store
